// ===============================================
// app_thmee
//
// Create by Will on 20/8/2023 19:40
// Copyright @xigou.All rights reserved.
// ===============================================

import 'package:flutter/material.dart';

import '../service/app_service.dart';
import 'multiple_themes_mode/app_theme_default.dart';

enum AppMultipleThemesMode { light, dark }

/// 多主题 如果需要就配置多个即可 方式类似 AppThemeDefault
Map<String, Map<AppMultipleThemesMode, ThemeData>> appMultipleThemesMode =
    <String, Map<AppMultipleThemesMode, ThemeData>>{
  'default': <AppMultipleThemesMode, ThemeData>{
    AppMultipleThemesMode.light: AppThemeDefault.lightTheme,
    AppMultipleThemesMode.dark: AppThemeDefault.darkTheme,
  },
};

/// 是否深色模式
bool isDarkMode(BuildContext context) {
  final themeMode = ThemeMode.values[AppService.to.themeMode.value];
  var isDark = false;
  if (themeMode == ThemeMode.system) {
    isDark = Theme.of(context).brightness == Brightness.dark;
  } else {
    isDark = themeMode == ThemeMode.dark;
  }
  return isDark;
}

/// 当前深色模式
///
/// [mode] system(默认)：跟随系统 light：普通 dark：深色
ThemeMode darkThemeMode(String mode) {
  var themeMode = ThemeMode.system;
  switch (mode) {
    case 'system':
      themeMode = ThemeMode.system;
      break;
    case 'dark':
      themeMode = ThemeMode.dark;
      break;
    case 'light':
      themeMode = ThemeMode.light;
      break;
    default:
      themeMode = ThemeMode.system;
      break;
  }
  return themeMode;
}

/// 当前多主题
String getMultipleThemesMode() {
  return AppService.to.multipleThemesMode.value;
}

/// 主题基础  以后主要拓展这个类型就好
class AppTheme {
  AppTheme(this.multipleThemesMode);
  String multipleThemesMode = 'default';

  /// 亮色主题 light
  ThemeData lightMode() {
    var lightTheme =
        appMultipleThemesMode['default']![AppMultipleThemesMode.light]!;
    if (appMultipleThemesMode[multipleThemesMode] != null) {
      lightTheme = appMultipleThemesMode[multipleThemesMode]![
          AppMultipleThemesMode.light]!;
    }
    return lightTheme;
  }

  /// 暗色主题 dark
  ThemeData darkMode() {
    var darkTheme =
        appMultipleThemesMode['default']![AppMultipleThemesMode.dark]!;
    if (appMultipleThemesMode[multipleThemesMode] != null) {
      darkTheme = appMultipleThemesMode[multipleThemesMode]![
          AppMultipleThemesMode.dark]!;
    }
    return darkTheme;
  }
}
